addpath('/Users/marcelomattar/Dropbox/Marcelo/UPenn/Documents/Projects/AdaptID/Scripts/Analyses/ROI_Analysis/1-back_adaptation_drawnFFAs');

subjectList = {...
    'N072912R'...
    'A080512A'...
    'R091412V'...
    'K091412S'...
    'M101012R'...
    };

ADAPT_t_thresh = 1.65;
%ADAPT_t_thresh = -Inf;
subjectsDir = '/Users/marcelomattar/Data/AdaptID/Subjects/';
FFAcontrast = 2; %1 for Faces-Objects, 2 for Faces-Scenes

numSubjects = length(subjectList);

overall_means = zeros(length(subjectList),1);
overall_stds = zeros(length(subjectList),1);

figure(1);

for subjIndx = 1:numSubjects
    
    % For subject A080512A, use the FFA mask based on the main effect
    % contrast
    if strcmp(subjectList{subjIndx},'A080512A')
        [averageBetas maskedBetas] = extractROImask(subjectList{subjIndx}, ADAPT_t_thresh, 3, subjectsDir);
    else
        [averageBetas maskedBetas] = extractROImask(subjectList{subjIndx}, ADAPT_t_thresh, FFAcontrast, subjectsDir);
    end
    
    averageBetas_array = zeros(size(maskedBetas));
    stdBetas_array = zeros(size(maskedBetas));
    for i=1:length(maskedBetas)
        averageBetas_array(i) = mean(maskedBetas{i});
        stdBetas_array(i) = std(maskedBetas{i});
    end
    
    subplot(1,numSubjects,subjIndx);
    bar(averageBetas_array);
    hold on;
    errorbar(1:length(maskedBetas),averageBetas_array,stdBetas_array,'.');
    axis([0 length(maskedBetas)+1 -80 80]);
    if subjIndx==1; ylabel('Average Beta value'); end;
    xlabel('Scan #');
    title(subjectList{subjIndx});
    
    overall_means(subjIndx) = mean(averageBetas_array);
    overall_stds(subjIndx) = std(averageBetas_array);
end

figure(2);
bar(overall_means);
hold on;
errorbar(1:numSubjects,overall_means,overall_stds,'.');
axis([0 numSubjects+1 -40 40]);
ylabel('Average Beta value');
xlabel('Subject #');
title('Summary of results');